import Fly from 'flyio/dist/npm/fly'
import env from '../config/env'


// 新建request对象
const request = new Fly()

// 请求超时时间
request.config.timeout = 60 * 1000000

// 统一请求前辍
request.config.baseURL = env.IHUB_PREFIX

// 请求拦截
request.interceptors.request.use((request) => {
})
// 返回拦截
request.interceptors.response.use(
    (response, promise) => {
        // 返回数据
        return promise.resolve(response.data)
    },
    (err, promise) => {
        // alert("ihub提示:"+err.message)
        return promise.resolve()
    }
)

/**
 * 返回当前登录人的信息
 * @param param
 * @returns {*}
 */
export const getUserInfo = (param) => {
    return request.post('/ihubApi/getUserInfo', Object.assign({ticket: sessionStorage.getItem('ihub-ticket')}, param));
}

/**
 *
 返回企业微信前端JSSDK调用必要的参数
 * @param param
 * @returns {*}
 */
export const getWechatInfo = (param) => {
    return request.post('/ihubApi/getWechatInfo', Object.assign({ticket: sessionStorage.getItem('ihub-ticket')}, param));
}

/**
 *返回企业微信前端JSSDK调用必要的参数(agentconfig，专用于外部联系人)
 * @param param
 * @returns {*}
 */
export const getWechatInfoFourAgentSign = (param) => {
    return request.post('/ihubApi/getWechatInfoFourAgentSign', Object.assign({
            ticket: sessionStorage.getItem('ihub-ticket')
        },
        param));
}
/**
 *获取所有文章信息接口
 * @param param
 * @returns {*}
 */
export const getContentData = (param) => {
    return request.post('/ihubApi/getContentData', Object.assign({ticket: sessionStorage.getItem('ihub-ticket')}, param));
}
/**
 *获取当前登录人的已认证已加好友的医生一栏
 * @param param
 * @returns {*}
 */
export const getDoctorlist = (param) => {
    return request.post('/ihubApi/getDoctorlist', Object.assign({ticket: sessionStorage.getItem('ihub-ticket')}, param));
}
/**
 *获取材料列表
 * @param param
 * @returns {*}
 */
export const getDocumentAll = (param) => {
    return request.get('/documentApi/getDocumentAll', Object.assign({token: sessionStorage.getItem('access-token')}, param));
}
/**
 *获取材料产品列表
 * @param param
 * @returns {*}
 */
export const getProductList = (param) => {
    return request.get('/documentApi/getProductList', {token: sessionStorage.getItem('access-token')});
}
/**
 *获取材料主题列表
 * @param param
 * @returns {*}
 */
export const getTopicList = (param) => {
    return request.get('/documentApi/getTopicList', {token: sessionStorage.getItem('access-token')});
}
/**
 *获取材料产品列表
 * @param param
 * @returns {*}
 */
export const getLabelList = (param) => {
    return request.get('/documentApi/getLabelList', {token: sessionStorage.getItem('access-token')});
}